import { Component, Input, OnInit } from '@angular/core';
import { AlertController } from '@ionic/angular';
import { AppGlobalService } from '../../shared/service/app-global.service';
import { HttpService } from '../../shared/service/http.service';

@Component({
  selector: 'app-new-index-head-tag',
  templateUrl: './new-index-head-tag.component.html',
  styleUrls: ['./new-index-head-tag.component.scss'],
})
export class NewIndexHeadTagComponent implements OnInit {

  @Input() tagData;
  appTypeCustom: any;
  constructor(
    private appGlobalService: AppGlobalService,
    private httpService: HttpService,
    private alertController: AlertController,
  ) { }

  ngOnInit() {

    // this.tagData.cssStyle = 'padding-bottom:1rem;padding-left:1rem;padding-right:1rem;';
    // const bodyStyles = window.getComputedStyle(document.body);
    // this.appTypeCustom = bodyStyles.getPropertyValue('--appTypeCustom').trim().replace('"', '').replace('"', '');

  }

  buttonClick(button) {
    try {
      if (button) {
        const params = {
          sessionId: localStorage.getItem("sessionId"),
          pageId: button.link.target,
          params: button.link.params
        };
        this.appGlobalService.goToForward(params);
      } else {
        // if (button.phone !== '') {
        //   this.call(button.phone, button.label);
        // }
      }
    } catch (error) {
      console.log('error----->' + JSON.stringify(error));
    }
  }
  async call(mobile, name) {
    const alert = await this.alertController.create({
      header: name,
      message: mobile,
      buttons: [
        {
          text: '取消',
          role: 'cancel',
          cssClass: 'secondary'
        }, {
          text: '拨打',
          handler: () => {
            this.httpService.changeCallNumber(mobile);
          }
        }
      ]
    });
    await alert.present();
  }


}
